<%@page import="sun.security.jgss.LoginConfigImpl"%>
<%@page import="dao.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户注册</title>

<style type="text/css">
body {
	font: normal 16px auto "Trebuchet MS", Verdana, Arial, Helvetica,
		sans-serif;
	color: #4f6b72;
	text-align: center;
	background: #E6EAE9;
}

#container {
	margin-left: auto;
	margin-right: auto;
	width: 600px;
	height: 600px;
	background: #f8f8f8;
	border: 2px solid #777;
	display: block;
	vertical-align: middle;
}

.ele {
	margin-top: 30px;
	margin-botton: 30px;
	text-align: center;
	width: 100%;
	display: block;
	vertical-align: middle;
}
</style>
<script src="./js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
	function checkData(){
		var username = document.getElementById("username").value.trim();
		var pass1 = document.getElementById("password").value.trim();
		var pass2 = document.getElementById("password2").value.trim();
		if(username != "" && pass1 != "" && pass2 !=""){
            var format1 = new RegExp("^[\\w]{4,20}$");               
            if(!format1.test(username)){
                alert("\u7528户名格式错误！");
                loginForm.username.focus();
                return false;
            }
            else if(!format1.test(pass1)){
                alert("\u5bc6码格式错误！");
                loginForm.passwd.focus();
                return false;
            }else{
				return true;
			}
		}else{
			alert("请填写完整");
			return false;
		}
	}
	function checkRepasswd() {
		if (regForm.passwd.value != regForm.repasswd.value) {
			regForm.repasswd.value = "";
			regForm.passwd.value = "";
			regForm.passwd.focus();
			document.getElementById("mes_pass2").innerHTML = "两次密码输入不 一致";
		} else {
			document.getElementById("mes_pass2").innerHTML = "&nbsp;";
		}
	}
	function getUserExists(){		
		$.ajax({
            type:"POST",
            url:"./servlet/UserManageServlet?action=getUserExists",
            data:{username:$("#username").val()},
            beforeSend:function(){},             
            success:function(data){
            	if(data == "exists"){           		
           			$("#tishi").html("该用户名已存在，请重新输入！");
           			$("#username").focus();
            	}else{
            		$("#tishi").html("&nbsp;");
            	}
            }            
         });
    }
</script>
</head>
<body>
	<div id="container">
		<form method="post" name="taskForm" onsubmit="return checkData()"
			action="./servlet/UserManageServlet?action=add">
			<div class="ele">
				<h2>用户注册</h2>
			</div>
			<div class="ele">
				<label> 用户名： </label> <input type="text" id="username"
					onblur="getUserExists()" name="username"> <span id="tishi"></span>
			</div>
			<div class="ele">
				<label> 密码： </label> <input type="password" id="password"
					name="password">
			</div>
			<div class="ele">
				<label> 密码确认： </label> <input type="password" id="password2"
					name="password2" onblur="checkRepasswd()"> <span
					id="des_pass2"></span>
			</div>
			<div class="ele">
				<input type="submit" value="提交"> &nbsp;&nbsp;&nbsp;&nbsp; <input
					type="reset" value="取消">
			</div>
		</form>
	</div>
	<%
	    if (request.getAttribute("success") != null) {
			String str = (String) request.getAttribute("success");
			if (str.equals("true"))
			    out.write("<script>alert('操作成功！点击确定后1秒返回登陆页面');setTimeout(function(){window.location.href='../login.jsp'},2000);</script>");
			else
			    out.write("<script>alert('操作失败！')</script>");
	    }
	%>
</body>
</html>